﻿@{
    ViewBag.Title = "ContentIndex";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}

@using LeSoft.Application.Code;
<script>
    var _organizeId = "@OperatorProvider.Provider.Current().CompanyId", _ItemId = "", _TypeId = "";;
    $(function () {
        InitialPage();
        GetTree();
        GetGrid();
    });
    //初始化页面
    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 141.5);
                $("#itemTree").setTreeHeight($(window).height() - 52);
            }, 200);
            e.stopPropagation();
        });
    }

    //加载树

    function GetTree() {
        var item = {
            height: $(window).height() - 52,
            url: "../../PropertyManage/CS_Polling/GetItemTreeJson",
            onnodeclick: function (item) {
                if (item.title == "type") {
                    _ItemId = "";
                    _TypeId = item.id;
                }
                else {
                    _ItemId = item.id;
                    _TypeId = "";
                }
                $('#btn_Search').trigger("click");
            }
        };
        //初始化
        $("#itemTree").treeview(item);
    }

    //加载表格
    function GetGrid() {
        var selectedRowIndex = 0;
        var $gridTable = $('#gridTable');
        var queryJson = $("#queryCondition").GetWebControls();
        queryJson["condition"] = $('#queryCondition').find('.dropdown-text').attr('data-value');
        queryJson["ItemId"] = _ItemId;
        queryJson["Type"] = _TypeId;
        queryJson["OrganizeId"] = _organizeId;
        $gridTable.jqGrid({
            url: "../../PropertyManage/CS_Polling/GetContentListJson",
            datatype: "json",
            postData: { queryJson: JSON.stringify(queryJson) },
            height: $(window).height() - 172.5,
            autowidth: true,
            colModel: [
                { label: "主键", name: "Id", index: "Id", hidden: true },
                { label: "编号", name: "Code", index: "Code", width: 150, align: "left" },
                { label: "名称", name: "Name", index: "Name", width: 150, align: "left" },
                { label: "标准要求", name: "Criterion", index: "Criterion", width: 300, align: "left" },
                { label: "检查方式", name: "CheckWay", index: "CheckWay", width: 150, align: "left" },
                {
                    label: "是否必填", name: "IsNeed", index: "IsNeed", width: 80, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        return cellvalue == 1 ? "<i value=" + cellvalue + " class=\"fa fa-toggle-on\"></i>" : "<i value=" + cellvalue + " class=\"fa fa-toggle-off\"></i>";
                    }
                },
                { label: "所属专业", name: "TypeName", index: "TypeName", width: 150, align: "left" },
                { label: "所属机构", name: "OrganizeId", index: "OrganizeId", width: 150, align: "left" },
                { label: "说明", name: "Memo", index: "Memo", width: 150, align: "left" }
            ],
            viewrecords: true,
            rowNum: 30,
            rowList: [30, 50, 100],
            pager: "#gridPager",
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function () {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        });
        //查询条件
        $("#queryCondition .dropdown-menu li").click(function () {
            var text = $(this).find('a').html();
            var value = $(this).find('a').attr('data-value');
            $("#queryCondition .dropdown-text").html(text).attr('data-value', value)
        });
        //查询事件
        $("#btn_Search").click(function () {
            var queryJson = $("#queryCondition").GetWebControls();
            queryJson["condition"] = $('#queryCondition').find('.dropdown-text').attr('data-value');
            queryJson["keyword"] = $('#txt_Keyword').val();
            queryJson["ItemId"] = _ItemId;
            queryJson["Type"] = _TypeId;
            queryJson["OrganizeId"] = _organizeId;
            $gridTable.jqGrid('setGridParam', {
                postData: { queryJson: JSON.stringify(queryJson) }, page: 1
            }).trigger('reloadGrid');
        });
        //查询回车
        $('#txt_Keyword').bind('keypress', function (event) {
            if (event.keyCode == "13") {
                $('#btn_Search').trigger("click");
            }
        });
    }

    //新增
    function btn_add() {
        dialogOpen({
            id: "Form",
            title: '添加内容',
            url: '/PropertyManage/CS_Polling/ContentForm',
            width: "800px",
            height: "520px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
            }
        });
    }

    //编辑
    function btn_edit() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (checkedRow(keyValue)) {
            dialogOpen({
                id: "Form",
                title: '编辑内容',
                url: '/PropertyManage/CS_Polling/ContentForm?keyValue=' + keyValue,
                width: "800px",
                height: "520px",
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            });
        }
    }

    //删除
    function btn_delete() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (keyValue) {
            $.RemoveForm({
                url: "../../PropertyManage/CS_Polling/RemoveContentForm",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#gridTable").trigger("reloadGrid");
                }
            })
        } else {
            dialogMsg('请选择需要删除的内容！', 0);
        }
    }
</script>

<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        <div class="west-Panel">
            <div class="panel-Title">巡检项目目录</div>
            <div id="itemTree"></div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="panel-Title">巡检内容信息</div>
            <div class="titlePanel">
                <div class="title-search">
                    <table>
                        <tr>
                            <td>
                                <div id="queryCondition" class="btn-group">
                                    <a class="btn btn-default dropdown-text" data-toggle="dropdown">选择条件</a>
                                    <a class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
                                    <ul class="dropdown-menu">
                                        <li><a data-value="Code">编号</a></li>
                                        <li><a data-value="Name">名称</a></li>
                                        <li hidden><a data-value="Iname">项目名称</a></li>
                                    </ul>
                                </div>
                            </td>
                            <td style="padding-left: 2px;">
                                <input id="txt_Keyword" type="text" class="form-control" placeholder="请输入要查询关键字" style="width: 200px;" />
                            </td>
                            <td style="padding-left: 5px;">
                                <a id="btn_Search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;查询</a>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="toolbar">
                    <div class="btn-group">
                        <a id="lr-replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                        <a id="lr-add" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增</a>
                        <a id="lr-edit" class="btn btn-default" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
                        <a id="lr-delete" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
                    </div>                
                    <script>$('.toolbar').authorizeButton()</script>
                </div>
            </div>
            <div class="gridPanel">
                <table id="gridTable"></table>
                <div id="gridPager"></div>
            </div>
        </div>
    </div>
</div>
